package com.kaige.asktaoplugin60.exception;

import com.kaige.asktaoplugin60.enums.ResultCodeEnum;
import io.swagger.models.auth.In;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class BusinessException extends RuntimeException{
    /**
     * 状态码
     */
    private Integer code;

    /**
     * 通过错误消息创建异常对象
     */
    public BusinessException(String message){
        super(message);
        this.code = ResultCodeEnum.FAIL.getCode();
    }

    /**
     * 通过状态码和错误消息创建异常对象
     * @param code 状态码
     * @param message 错误消息
     */
    public BusinessException(Integer code, String message){
        super(message);
        this.code = code;
    }

    /**
     * 接收枚举类型对象
     * @param resultCodeEnum 错误枚举对象
     */
    public BusinessException(ResultCodeEnum resultCodeEnum){
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

}
